Add WARN() and generic WARN_ON().
authorkfraser@localhost.localdomain <kfraser@localhost.localdomain>
Tue, 27 Mar 2007 14:53:45 +0000 (15:53 +0100)
committerkfraser@localhost.localdomain <kfraser@localhost.localdomain>
Tue, 27 Mar 2007 14:53:45 +0000 (15:53 +0100)
Based on a patch by Jan Beulich <jbeulich@novell.com>

Signed-off-by: Keir Fraser <keir@xensource.com>
12 files changed:
xen/arch/ia64/linux-xen/mca.c
xen/arch/powerpc/backtrace.c
xen/arch/x86/traps.c
xen/drivers/char/console.c
xen/include/asm-ia64/bug.h
xen/include/asm-ia64/linux-xen/asm/iosapic.h
xen/include/asm-powerpc/bug.h
xen/include/asm-powerpc/debugger.h
xen/include/asm-x86/bug.h
xen/include/asm-x86/x86_32/bug.h
xen/include/asm-x86/x86_64/bug.h
xen/include/xen/lib.h

index f1f47c68e25bed07f63f0a46c867fb2f9cd349de..68fa284e2dfaaf35ed854b058698db312e47ef55 100644 (file)
@@ -396,16 +396,6 @@ ia64_log_queue(int sal_info_type, int virq)
 #ifdef CONFIG_ACPI
 
 #ifdef XEN
-/**
- *     Copy from linux/include/asm-generic/bug.h
- */
-#define WARN_ON(condition) do { \
-       if (unlikely((condition)!=0)) { \
-               printk("Badness in %s at %s:%d\n", __FUNCTION__, __FILE__, __LINE__); \
-               dump_stack(); \
-       } \
-} while (0)
-
 /**
  *     Copy from linux/kernel/irq/manage.c
  *
index badbd9d2e5a0103ec62c5edf7340c30c91f7edec..7cf8032af76db7ea2d9c8976d9f626962e83e080 100644 (file)
@@ -205,21 +205,6 @@ void show_backtrace_regs(struct cpu_user_regs *regs)
     console_end_sync();
 }
 
-void __warn(char *file, int line)
-{
-    ulong sp;
-    ulong lr;
-
-    console_start_sync();
-    printk("WARN at %s:%d\n", file, line);
-
-    sp = (ulong)__builtin_frame_address(0);
-    lr = (ulong)__builtin_return_address(0);
-    backtrace(sp, lr, lr);
-
-    console_end_sync();
-}
-
 void dump_execution_state(void)
 {
     struct cpu_user_regs *regs = guest_cpu_user_regs();
index 2423ad54935d7b2d9579c8f91c545fa53a066a13..bab363e7471df62c2077c7f127a8cea07a39b392 100644 (file)
@@ -637,29 +637,35 @@ asmlinkage int do_invalid_op(struct cpu_user_regs *regs)
          memcmp(bug.ud2, "\xf\xb", sizeof(bug.ud2)) ||
          (bug.ret != 0xc2) )
         goto die;
+    eip += sizeof(bug);
 
     id = bug.id & 3;
-    if ( id == BUGFRAME_rsvd )
-        goto die;
 
     if ( id == BUGFRAME_dump )
     {
         show_execution_state(regs);
-        regs->eip += sizeof(bug);
+        regs->eip = (unsigned long)eip;
         return EXCRET_fault_fixed;
     }
 
-    /* BUG() or ASSERT(): decode the filename pointer and line number. */
-    ASSERT((id == BUGFRAME_bug) || (id == BUGFRAME_assert));
-    eip += sizeof(bug);
+    /* WARN, BUG or ASSERT: decode the filename pointer and line number. */
     if ( !is_kernel(eip) ||
          __copy_from_user(&bug_str, eip, sizeof(bug_str)) ||
          memcmp(bug_str.mov, BUG_MOV_STR, sizeof(bug_str.mov)) )
         goto die;
+    eip += sizeof(bug_str);
 
     filename = is_kernel(bug_str.str) ? (char *)bug_str.str : "<unknown>";
     lineno   = bug.id >> 2;
 
+    if ( id == BUGFRAME_warn )
+    {
+        printk("Xen WARN at %.50s:%d\n", filename, lineno);
+        show_execution_state(regs);
+        regs->eip = (unsigned long)eip;
+        return EXCRET_fault_fixed;
+    }
+
     if ( id == BUGFRAME_bug )
     {
         printk("Xen BUG at %.50s:%d\n", filename, lineno);
@@ -668,13 +674,13 @@ asmlinkage int do_invalid_op(struct cpu_user_regs *regs)
         panic("Xen BUG at %.50s:%d\n", filename, lineno);
     }
 
-    /* ASSERT(): decode the predicate string pointer. */
+    /* ASSERT: decode the predicate string pointer. */
     ASSERT(id == BUGFRAME_assert);
-    eip += sizeof(bug_str);
     if ( !is_kernel(eip) ||
          __copy_from_user(&bug_str, eip, sizeof(bug_str)) ||
          memcmp(bug_str.mov, BUG_MOV_STR, sizeof(bug_str.mov)) )
         goto die;
+    eip += sizeof(bug_str);
 
     predicate = is_kernel(bug_str.str) ? (char *)bug_str.str : "<unknown>";
     printk("Assertion '%s' failed at %.50s:%d\n",
index ef11d735ba91df35381b7a9d3943c8223198bd9d..87786f152fad1c109ba270b12a251133d732db1e 100644 (file)
@@ -900,12 +900,18 @@ void panic(const char *fmt, ...)
 void __bug(char *file, int line)
 {
     console_start_sync();
-    printk("BUG at %s:%d\n", file, line);
+    printk("Xen BUG at %s:%d\n", file, line);
     dump_execution_state();
-    panic("BUG at %s:%d\n", file, line);
+    panic("Xen BUG at %s:%d\n", file, line);
     for ( ; ; ) ;
 }
 
+void __warn(char *file, int line)
+{
+    printk("Xen WARN at %s:%d\n", file, line);
+    dump_execution_state();
+}
+
 /*
  * Local variables:
  * mode: C
index 2caf275c39af23188e36100301a160b616695eee..a13a76bf8ca739815f7b7439a22cab5db966d848 100644 (file)
@@ -2,5 +2,6 @@
 #define __IA64_BUG_H__
 
 #define BUG() __bug(__FILE__, __LINE__)
+#define WARN() __warn(__FILE__, __LINE__)
 
 #endif /* __IA64_BUG_H__ */
index f289349ea0cf48c13c402c05230fcf096a080cab..a94e5f53da211643bbb36b72d5112346ee6b1bbe 100644 (file)
@@ -123,13 +123,6 @@ static inline void list_move(struct list_head *list, struct list_head *head)
 
 #define move_irq(x)
 
-#define WARN_ON(condition) do { \
-       if (unlikely((condition)!=0)) { \
-               printk("Badness in %s at %s:%d\n", __FUNCTION__, __FILE__, __LINE__); \
-               dump_stack(); \
-       } \
-} while (0)
-
 #ifdef nop
 #undef nop
 #endif
index 20d7d4bfb9f39777a43c8274a82f6c28902a0c6e..65caa37171c12d8cec9e0290a94da5e4f9eac0d4 100644 (file)
@@ -2,5 +2,6 @@
 #define __POWERPC_BUG_H__
 
 #define BUG() __bug(__FILE__, __LINE__)
+#define WARN() __warn(__FILE__, __LINE__)
 
 #endif /* __POWERPC_BUG_H__ */
index 4e4cea5df2ccebce3dc07d4f6ca6b1a92092e332..8a979d0e115484242db738b2a044ca8564d43bbe 100644 (file)
@@ -67,10 +67,6 @@ static inline void unimplemented(void)
 #endif
 }
 
-extern void __warn(char *file, int line);
-#define WARN() __warn(__FILE__, __LINE__)
-#define WARN_ON(_p) do { if (_p) WARN(); } while ( 0 )
-
 extern void __attn(void);
 #define ATTN() __attn();
 
index d09e3ea7a0866eed0a99670890f9386cbb74d40c..975576185c0b5649ee280ce37ada5e0ab02c3abd 100644 (file)
@@ -14,8 +14,8 @@ struct bug_frame {
 } __attribute__((packed));
 
 #define BUGFRAME_dump   0
-#define BUGFRAME_bug    1
-#define BUGFRAME_assert 2
-#define BUGFRAME_rsvd   3
+#define BUGFRAME_warn   1
+#define BUGFRAME_bug    2
+#define BUGFRAME_assert 3
 
 #endif /* __X86_BUG_H__ */
index 9e2c4ce695ddf6d0b0963c9864f5ec31f10d568b..20a9137063e88b7152d0b87dea9bc410481cebfb 100644 (file)
@@ -12,6 +12,12 @@ struct bug_frame_str {
         "ud2 ; ret $%c0"                                \
         : : "i" (BUGFRAME_dump) )
 
+#define WARN()                                          \
+    asm volatile (                                      \
+        "ud2 ; ret $%c0 ; .byte 0xbc ; .long %c1"       \
+        : : "i" (BUGFRAME_warn | (__LINE__<<2)),        \
+            "i" (__FILE__) )
+
 #define BUG()                                           \
     asm volatile (                                      \
         "ud2 ; ret $%c0 ; .byte 0xbc ; .long %c1"       \
index 5676f3878cf8c8a5e86d925c58a86a7ea139ff4a..3fa5debfa74f2ae73d9d0b33249a573c55fc8be2 100644 (file)
@@ -12,6 +12,12 @@ struct bug_frame_str {
         "ud2 ; ret $%c0"                                \
         : : "i" (BUGFRAME_dump) )
 
+#define WARN()                                          \
+    asm volatile (                                      \
+        "ud2 ; ret $%c0 ; .byte 0x48,0xbc ; .quad %c1"  \
+        : : "i" (BUGFRAME_warn | (__LINE__<<2)),        \
+            "i" (__FILE__) )
+
 #define BUG()                                           \
     asm volatile (                                      \
         "ud2 ; ret $%c0 ; .byte 0x48,0xbc ; .quad %c1"  \
index f5f59441f1f2c7b3cb130f601a91d35e92df1900..3145542b254000e53a3e9cc92673405f0f78c509 100644 (file)
 #include <asm/bug.h>
 
 void __bug(char *file, int line) __attribute__((noreturn));
+void __warn(char *file, int line);
 
-#define BUG_ON(_p) do { if (_p) BUG(); } while ( 0 )
+#define BUG_ON(p)  do { if (p) BUG();  } while (0)
+#define WARN_ON(p) do { if (p) WARN(); } while (0)
 
 /* Force a compilation error if condition is true */
 #define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2 * !!(condition)]))